//
//  BPChangePhoneViewController.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/9/2.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "BPChangePhoneViewController.h"

@interface BPChangePhoneViewController ()

@end

@implementation BPChangePhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = pinkBtnColor;
    
    NSArray *placeArry = [NSArray arrayWithObjects:@"请输入手机号码",@"请输入您的验证码", nil];
    CGFloat topDistance = 30.0f;
    CGFloat textH = 20.0f;
    CGFloat bottomDistance = 10.0f;
    CGFloat textX = 20.0f;
    CGFloat textW = BPScreenW - 40.0f;
    
    _phone = [[UITextField alloc] initWithFrame:CGRectMake(textX,BPScreenNavY + topDistance + (topDistance + bottomDistance + textH) * 0, textW, textH)];
    _phone.placeholder = placeArry[0];
    [self.view addSubview:_phone];
    
    _message = [[UITextField alloc] initWithFrame:CGRectMake(textX,BPScreenNavY + topDistance + (topDistance + bottomDistance + textH) * 1, textW, textH)];
    _message.placeholder = placeArry[1];
    [self.view addSubview:_message];
    
    for (int i = 0; i < 3; i ++) {
        BPLineView *line = [[BPLineView alloc] initWithFrame:CGRectMake(textX, BPScreenNavY + (topDistance + bottomDistance + textH) * (i+1), textW, 1.0)];
        [self.view addSubview:line];
    }
    
    UIButton *sendMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sendMessageBtn.backgroundColor = [UIColor blackColor];
    CGFloat messageH = 30.0f;
    CGFloat messageY = _message.y + 20.0f - messageH;
    CGFloat messageW = 90.0f;
    CGFloat messageX = BPScreenW - 20.0f - messageW;
    sendMessageBtn.frame = CGRectMake(messageX, messageY, messageW, messageH);
    [sendMessageBtn.layer setMasksToBounds:YES];
    [sendMessageBtn.layer setCornerRadius:3.0f];
    [sendMessageBtn setTitle:@"发送短信验证码" forState:UIControlStateNormal];
    sendMessageBtn.titleLabel.font = [UIFont boldSystemFontOfSize:12.0f];
    [sendMessageBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sendMessageBtn addTarget:self action:@selector(sendMessage) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sendMessageBtn];
    
    UIButton *registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    registerBtn.backgroundColor = BPGlobaThemeColor;
    CGFloat btnW = (340.0 / 640.0)*BPScreenW;
    CGFloat btnH = 50.0;
    CGFloat btnY = _message.y + 20.0f + 10.0f + 50.0f;
    CGFloat btnX = (BPScreenW - btnW) / 2.0;
    registerBtn.frame = CGRectMake(btnX, btnY, btnW, btnH);
    [registerBtn.layer setMasksToBounds:YES];
    [registerBtn.layer setCornerRadius:25.0f];
    [registerBtn setTitle:@"号码重置" forState:UIControlStateNormal];
    registerBtn.titleLabel.font = [UIFont boldSystemFontOfSize:23.0f];
    [registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [registerBtn addTarget:self action:@selector(reBPPhone) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerBtn];

    // Do any additional setup after loading the view.
}

- (void)sendMessage{
    if ([self checkPhoneNumber] == YES) {
        
    }
}

- (void)reBPPhone{
    if ([self checkPhoneNumber] == YES) {
        
    }
}

- (BOOL)checkPhoneNumber
{
    NSString *phoneNumber = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneNumber];
    
    BOOL isMatch = [pred evaluateWithObject:_phone.text];
    
    if (!isMatch) {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }else
    {
        return YES;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
